
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>局部打印案例</title>
<script type="text/javascript">   
    function doPrint() {    
        dd=window.document.body.innerHTML
        bdhtml=document.getElementById("print").innerHTML;      
        window.document.body.innerHTML=bdhtml; 
        window.print();    
        window.document.body.innerHTML=dd;//恢复页面
}    
</script>
 
</head>

<!-- <body style="background-image: url(1.png);background-color: #000000;"> -->
<body >
<p>1不需要打印的地方</p>
<p>2这里不要打印啊</p>
<div id="print">
    <h1>打印标题</h1>
    <p>打印内容~~</p><h1>打印标题</h1>
    <p>打印内容~~</p><h1>打印标题</h1>
    <p>打印内容~~</p><h1>打印标题</h1>
    <p>打印内容~~</p><h1>打印标题</h1>
    <p>打印内容~~</p>
</div>

<button type="button" onclick="doPrint()">打印</button>
<p>不打印的地方啊哈哈哈哈</p>
<p>2</p>
</body>